<?php


namespace app\index\model;
use think\Db;
use think\Model;


class Xmsf extends Model
{


    protected $table = 'xt_xmsf';

    //根据项目代号返回结果  --单项
    public  function GetXmsfByXmdh($xmdh){
        return $res = Db::table('xt_xmsf')->where('xmdh',$xmdh)->select();
    }


    //根据项目  检验目的代号  查询
    public  function GetxmsfByData($data){
        $xmdh = trim($data['xmdh']);
        $yqdh = trim($data['yqdh']);
        //$zhsf = trim($data['zhsf']);
        if (isset($data['khdh'])) {
            $khdh = $data['khdh'];
        } else {
            $khdh = '';
        }
        $res = Db::table('xt_xmsf')->where(['xmdh'=>$xmdh,'yqdh'=>$yqdh,'khdh'=>$khdh])->select();
        if(Empty($res)){
            return false;
        }
        return $res;
    }


    //根据项目 检验目的代号  插入  结果
    public function InsertxmsfByXmdh($data)
    {
        $xmdh = trim($data['xmdh']);
        $yqdh = trim($data['yqdh']);
        $xmsf = trim($data['xmsf']);
        $starttime = $data['starttime'];
        $endtime = $data['endtime'];
        //$pv  = 6 ;
        //$jb  = 3 ;
        if (isset($data['khdh'])) {
            $khdh = $data['khdh'];
        } else {
            $khdh = '';
        }

        //开始添加
        $res = Db::execute("INSERT INTO xt_xmsf ( yqdh, xmdh, brlb, xmsf, khdh,starttime, endtime, pv, jb )
                 VALUES ( :yqdh, :xmdh, '[none]', :xmsf, :khdh, :starttime, :endtime, '6', '3' )",
            ['yqdh' => $yqdh, 'xmdh' => $xmdh, 'xmsf'=>$xmsf,'khdh'=>$khdh,'starttime' => $starttime, 'endtime' => $endtime]);


        if ($res) {
            return true;
        }

        return false;

    }

}